// src/main.js
import Vue from 'vue';
import App from './App.vue';
import router from './router';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios';

Vue.config.productionTip = false;

// 挂载 axios 到全局
Vue.prototype.$axios = axios;

// 使用 Element UI
Vue.use(ElementUI);

// 设置 axios 基础地址
axios.defaults.baseURL = 'http://localhost:8080';

// 请求拦截器：自动携带 JWT token
axios.interceptors.request.use(config => {
  const token = localStorage.getItem('token');
  if (token) {
    config.headers['Authorization'] = 'Bearer ' + token;
  }
  return config;
});

new Vue({
  router,
  render: h => h(App)
}).$mount('#app');